﻿using System;
using JESAI.HttpRequestMonitor.Core.Abstracts;
using JESAI.HttpRequestMonitor.Init;
using Microsoft.AspNetCore.Builder;

namespace Microsoft.Extensions.DependencyInjection
{
    public static class DependencyInjectionExtensions
    {
        public static IHttpRequestMonitorInitializer InitHttpRequestMonitor(this IApplicationBuilder app)
        {
            return new HttpRequestMonitorInitializer(app);
        }

        public static IHttpRequestMonitorInitializer InitStorage(this IHttpRequestMonitorInitializer initializer)
        {
            var storage = initializer.ApplicationBuilder.ApplicationServices.GetRequiredService<IRequestMonitorStorage>() ?? throw new ArgumentNullException("Storage Service Not Found");
            storage.InitAsync().Wait();

            return initializer;
        }
    }
}